package com.operator.Activitys.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.operator.Activitys.R;
import com.operator.Activitys.adapter.base.BaseRecyclerViewAdapter;
import com.operator.Activitys.bean.SearchShop;
import com.operator.Activitys.utils.FrescoUtils;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 项目名称：金泽云 手机app
 * 类描述：
 * 创建人：张飞祥
 * 创建时间：2018/5/24 9:27
 * 修改人：张飞祥
 * 修改时间：2018/5/24 9:27
 * 修改备注：
 */
public class SearchShopAdapter extends BaseRecyclerViewAdapter {


    //全局上下文
    private Context mContext;
    //数据源
    private List<SearchShop> mList;

    public SearchShopAdapter(Context context, List<SearchShop> list) {
        super(context, list);
        this.mContext = context;
        this.mList = list;
    }

    @Override
    protected int getLayoutItemResId() {
        return R.layout.item_search_shop;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        if (viewHolder instanceof SearchShopViewHolder) {
            final SearchShopViewHolder holder = (SearchShopViewHolder) viewHolder;

            //将数据保存在itemView的Tag中，以便点击时进行获取
            viewHolder.itemView.setTag(position);

            //TODO 设置数据
            final SearchShop shop = mList.get(position);

            /**
             * 填充 数据源
             */
            //头像
            FrescoUtils.loadImage(shop.getImgUrl(), holder.svItemShopIcon);
            //店铺名称
            holder.tvItemShopName.setText(shop.getStoreName());
            //店铺电话
            holder.tvItemShopPhone.setText("电话：" + shop.getMobile());

            //最后一条 不显示底线
            if ((position + 1) == mList.size())
                holder.viewShopBottomLine.setVisibility(View.GONE);


        }
    }

    //TODO 清空所有数据
    public void removeAllData(){
        mList.clear();
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new SearchShopViewHolder(view);
    }

    /**
     * 评论  ViewHolder
     */
    public class SearchShopViewHolder extends RecyclerView.ViewHolder {

        //店铺 头像
        @Bind(R.id.sv_item_shop_icon)
        SimpleDraweeView svItemShopIcon;
        //店铺名称
        @Bind(R.id.tv_item_shop_name)
        TextView tvItemShopName;
        //店铺电话
        @Bind(R.id.tv_item_shop_phone)
        TextView tvItemShopPhone;
        //底线
        @Bind(R.id.view_shop_bottom_line)
        View viewShopBottomLine;

        public SearchShopViewHolder(View itemView) {
            super(itemView);
            //绑定控件
            ButterKnife.bind(this, itemView);
            //item 适配
            AutoUtils.autoSize(itemView);
        }
    }
}
